class CommentsController < ApplicationController
before_action :set_comment, only: [:destroy]

  def new

  	@user = User.find(params[:user_id])

  	@comment = Comment.new

  end

  def create
  	@user = User.find(params[:user_id])
  	@comment = User.find(params[:user_id]).comments.new(comment_params)
  	if @comment.save

  		redirect_to @user, notice: "Comment successfully added!"
  	else
  		render new_comment_path
  	end

  end

  def destroy
  	# exit
  	@user = User.find(params[:user_id])
  	@comment = Comment.find(params[:id])
  	@comment.destroy
  	redirect_to @user, notice: "Comment successfully deleted"
	# exit
  end

	private

	def comment_params
		params.require(:comment).permit(:author, :content)
	end

	def set_comment
	@comment = Comment.find(params[:id])
	end

end
